﻿using System;
using System.Collections.Generic;
using DesignerScripts;

namespace Script.Structs.Pawn
{
    public class PawnControlState
    {
        ///<summary>
        ///当前可行动列表
        ///</summary>
        Dictionary<ActionType,bool> canActionList;
        

        /// <summary>
        /// 默认行动
        /// </summary>
        public ActionType DefaultAction;
        public PawnControlState(){
            canActionList = new Dictionary<ActionType, bool>();
            Origin();
        }
        
        /// <summary>
        /// 重置
        /// </summary>
        public void Origin(){
            canActionList.Clear();
            canActionList.Add(ActionType.select,true);
            DefaultAction = ActionType.select;
        }
        
        /// <summary>
        /// 判断是否还有可以执行的行动
        /// </summary>
        /// <returns></returns>
        public bool CanAction()
        {
            return canActionList.Keys.Count > 0;
        }
        
        /// <summary>
        /// 覆盖新的行动列表 清除旧的换成新的
        /// </summary>
        /// <param name="actionList"></param>
        public void CoverActionList(ActionType[] actionList)
        {
            canActionList.Clear();
            foreach (var actionType in actionList)
            {
                canActionList.Add(actionType,true);
            }
        }
        
        /// <summary>
        /// 增加新的行动列表
        /// </summary>
        /// <param name="actionList"></param>
        public void AddActionList(ActionType[] actionList)
        {
            foreach (var actionType in actionList)
            {
                if (!canActionList.ContainsKey(actionType))
                {
                    canActionList.Add(actionType,true);
                } 
            }
        }
        
        /// <summary>
        /// 可执行行动删除
        /// </summary>
        /// <param name="actionType"></param>
        public void RemoveAction(ActionType actionType)
        {
            if (canActionList.ContainsKey(actionType))
            {
                canActionList.Remove(actionType);
            }
        }
        
        /// <summary>
        /// 所有可执行行动删除
        /// </summary>
        /// <param name="actionType"></param>
        public void RemoveAllAction()
        {
            canActionList.Clear();
        }
        
        /// <summary>
        /// 检查是否可以行动
        /// </summary>
        /// <param name="actionType"></param>
        public bool CheckCanAction(ActionType actionType)
        {
            return canActionList.ContainsKey(actionType); 
        }
        
        /// <summary>
        /// 返回可在执行行动状态列表
        /// </summary>
        /// <param name="actionName"></param>
        public Dictionary<ActionType,bool> GetActionList()
        {
           return canActionList;
        }
        
        public static PawnControlState origin = new PawnControlState();
    }
}